<template>
	<view>
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="dataform.telephone" placeholder="电话" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="dataform.password" placeholder="密码" type="password" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="default">注册</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataform: {
					"telephone": "12345678912",
					"password": "123456"
				}
			}
		},
		methods: {
			login() {
				console.log("===");
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					header: {"content-type":"application/json"},
					data: this.dataform,
					success: res => {
						if(res.data.success){
							//登录成功
							uni.showToast({
								title: '成功',
								icon: 'none'
							});
							uni.navigateTo({
								url: '/pages/index/index'
							});
						}else{
							// 登录失败
							uni.showToast({
								title: '失败',
								icon: 'none'
							});
						}
					},
					fail: () => {
						// 网络错误
					},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>

</style>
